#ifndef CQTOPENCVVIEWERGL_H
#define CQTOPENCVVIEWERGL_H

#include <QGLWidget>
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <QMessageBox>

#include "qrreader.h"


class CQtOpenCVViewerGl : public QGLWidget
{
    Q_OBJECT
public:
    explicit CQtOpenCVViewerGl(QWidget *parent = 0);
    void setStaticView(bool isStatic);
private:
    bool mSceneChanged; /// Indicates when OpenGl view is to be redraw
    bool drawCenterSquareLine; /// controls the animation of drawing the center square
    bool isStaticView; /// Used to redimension the openGL render window for static images



    QImage mRenderQtImg; /// Qt Image to be rendered
    cv::Mat mOriginImage; /// original OpenCV image to be shown

    QColor mBgColor; /// Background Color

    int mOutH; /// resized image height
    int mOutW; /// resized image width
    float mImratio; /// height/width ratio

    int mPosX; /// Top Left X position to reder image in the center of the widget
    int mPosY; /// Top Left Y position to reder image in the center of the widget

    qrReader reader; /// QrCode reader object

    QMessageBox messageBox;


protected:
    // ---------> OpenGl methods
    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);
    // <--------- OpenGl methods
    void updateScene(); /// Forces a Scene to Update
    void renderImage(); /// Render Image on openGL frame

    void paintCentralSquare(int imageWidth); /// paint square where the qrCode should be positionend

    void timerEvent(QTimerEvent *); /// timer event to animate the screen

signals:
    void imageSizeChanges (int outW, int outH); /// used to resize image outside the widget

public slots:
    bool showImage (cv::Mat image); /// Used to set the Image to be viewed
    
};

#endif // CQTOPENCVVIEWERGL_H
